<include file="Public:header" />

<script src="__ROOT__/Public/js/kindeditor/kindeditor.js"></script>
<script type="text/javascript">
var timeoutid ;
var root_url = "__ROOT__/";
var app_url = "__APP__/";
var url_url = "__URL__/";
              
$(document).ready(function(){
	
	gbookshow();
	
	KE.init({
                  id : 'contents',
                  items : ['emoticons', 'image']
	});
	
	
});

function gbookshow(p){
	
	if(arguments.length   ==   0) {
			p = 0;
	}
	if(p<0){
		p = "";
	}
	
	gbook_id = "guestbook";
	gbook = $("#guestbook");
	gbook.html('');
	
	/*img_w_max = "500";
	img_h_max = "500";*/
	
	if(p){
		url = "__APP__/post/gbook/p/"+p;
	}
	else{
		url = "__APP__/post/gbook/"
	}
	$("<table id='g_table'></table>").appendTo("#guestbook");
	t = $("#g_table");
	t.width(550).css({"border":"0px","cellpadding":"0px","cellspacing":"0px"});
	
	
	
	$.post(url,{},function(s){
		r = eval("("+s+")");
		rdata = r['data'];
		book = rdata['gbook'];
		rpage = rdata['page'];
		$("<tr ></tr>").appendTo("#g_table");
		$('<td></td>').appendTo("#g_table tr:last");
		$('<div></div>').addClass('post').appendTo("#g_table tr:last td:eq(0)");
		$('<p></p>').addClass('line').appendTo(".post");
		
		
		if(rdata['user']){
			
			$(".line").html("欢迎您 <span>"+rdata['user']+"</span>，请<span>留言</span>。<span class='gbook_page'></span>");
			
			
			
			
			$("<tr id='g_post'></tr>").css({"display":"none"}).appendTo("#g_table");
			
			//$("<tr id='g_post'></tr>").appendTo("#g_table");
			
			$("<td></td>").appendTo("#g_table tr:last");
			$("<div></div>").addClass("entry").appendTo("#g_table tr:last td:eq(0)");
			
			//$("<form></from>").appendTo('#g_table tr:last td:eq(0) .entry');
			
			$('#g_table tr:last td:eq(0) .entry').html("<form><p>留言内容：<br><textarea cols=60 rows=8 name='contents' id='contents'></textarea></p><p><input type='button' class='links' value='提  交' onclick='show_post(\"__APP__\")'/></p></from>");
		  	//$("<p>留言内容：<br><textarea cols=60 rows=5 name='contents' id='contents'></textarea></p>").appendTo('.entry form');	
			//$('.entry form').html("<p>留言内容：<br><textarea cols=60 rows=5 name='contents' id='contents'></textarea></p>");
		  	//$("<p><input type='button' class='links' value='提  交' onclick='show_post(\"__APP__\")'/></p>").appendTo('.entry'); 
		  	$("<p class='line'></p>").appendTo('.entry');
		  	
			$(".line span:eq(1) ").bind("click", show_post);
			
		}
		else{
			$(".line").html("请<a href='__APP__/public/login'> 登录 </a>后留言。<span class='gbook_page'></span>")
		}
		
		if(book){
		//ti = t.find("tr").length;
			bL = book.length;
			for(i=0;i<bL;i++){
				$("<tr ></tr>").appendTo("#g_table");
				$('<td></td>').appendTo("#g_table tr:last");
				$("<div></div>").addClass('post').appendTo("#g_table tr:last td:eq(0)");
				$("<h3></h3>").addClass('title').appendTo("#g_table tr:last td:eq(0) .post");
				$("#g_table tr:last td:eq(0) h3").html(book[i]['contents']);
				
				//给图片添加一个超链接 来访问原始尺寸图片;
				if($("#g_table tr:last td:eq(0) h3 img").attr("src")){
					
					//添加图片显示的尺寸限制;
					img_w = $("#g_table tr:last td:eq(0) h3 img").width();
					img_h = $("#g_table tr:last td:eq(0) h3 img").height();
					img_size = img_limit(img_w,img_h);	//图片尺寸限制函数;
					//alert (img_size);
					$("#g_table tr:last td:eq(0) h3 img").width(img_size[0]).height(img_size[1]);
					
				
					img_url = $("#g_table tr:last td:eq(0) h3 img").attr("src");
					$("#g_table tr:last td:eq(0) h3 img").wrap("<a href='"+img_url+"' target='_blank'></a>");
				}
				//
				var admin_str = "";
				if(rdata['glevel'] && rdata['glevel'] == "会长") {
					admin_str = "<a href='"+app_url+"post/post_del/gid/"+book[i]['gid']+"'>[删除]</a>";
				}
				user_str = "由 <b><span class='guest_name'>"+book[i]['acc_name']+"</span></b> 在 "+book[i]['gtime']+"发布。"+admin_str;
			   	$("<p></p>").addClass('meta').appendTo("#g_table tr:last td:eq(0) .post");	      
		        $("#g_table tr:last td:eq(0) .meta").html(user_str);  
		        $("<p></p>").addClass('item').appendTo("#g_table tr:last td:eq(0) .post");	                                        
		    }
		   	
		}
		else{
			$("<tr ></tr>").appendTo("#g_table");
			$('<td></td>').appendTo("#g_table tr:last");
			$("<div id = 'noguest'></div>").addClass('post').appendTo("#g_table tr:last td:eq(0)");
			$("<p class='meta'>暂无留言。</p>").appendTo("#noguest");
			
		}
		pageFormat(rpage);
		armoryinfo();
		
	});
	
	
	
}

function pageFormat(page){
	
	page_arr = page;
	first_css = "";
	end_css = "";
	pre_css = "";
	next_css = "";
	
	page_next = "";
	page_pre = "";
	istart = 1+(((page_arr['nowPage']-1)/page_arr['rollPage']|0))*page_arr['rollPage'];
	iend = istart+page_arr['rollPage']-1;
	
	if(page_arr['nowPage'] == iend){
		next = iend+1;
		page_next = "  <a href='javascript:gbookshow("+next+")' class = '"+next_css+"'>[>]</a>";
		if(next> page_arr['totalPages']){
			next = page_arr['totalPages'];
		}
		if(page_arr['nowPage'] == page_arr['totalPages']){
			page_next = "";
		}
	}
	
	
	if(page_arr['nowPage'] == istart){
		pre = istart-1;
		page_pre =  "  <a href='javascript:gbookshow("+pre+")' class = '"+pre_css+"'>["+page_arr['config']['prev']+"]</a>  ";
		if(pre<0){
			pre = 1;
		}
		if(page_arr['nowPage'] == 1){
			page_pre =  "";
		}
	}
	
	if(iend > page_arr['totalPages']){
		iend = page_arr['totalPages'];
	}
	
	if(page_arr['nowPage'] <= page_arr['rollPage']){
		first_css = "page-off";
		istart = 1;
	}
	
	if(page_arr['nowPage'] > (page_arr['coolPage']-1)*page_arr['rollPage'] || page_arr['totalPages'] < page_arr['rollPage']){
		end_css = "page-off";
	}
	var page_num = "";
	
	for(i=istart;i<=iend;i++){
		if(i == page_arr['nowPage']){
			num_str = "    "+i+"    ";
			
		}
		else{
			num_str = "   <a href='javascript:gbookshow("+i+")'>["+i+"]</a>   ";
		}
		page_num = page_num + num_str;
	}
	
	//
	page_first = "  <a href='javascript:gbookshow(1)' class = '"+first_css+"'>["+page_arr['config']['first']+"]</a>  ";
	
	page_end = "  <a href='javascript:gbookshow("+page_arr['totalPages']+")' class = '"+end_css+"'>["+page_arr['config']['last']+"]</a>  ";
	
	page_str = page_first + page_pre + page_num + page_next + page_end;
	
	$('.gbook_page').html(page_str);
	$(".page-off").bind("click", function() { return false; }); 
	
	
}


function armoryinfo(){
	
	var name_arr = new Array;
	var item_arr = new Array;
	$('.guest_name').each(function(i){
		name_arr[i] = $(this).html();
	});
	
	$.post('__APP__/member/ajaxarmory',{'name_arr[]':name_arr},
		function(s){
			r = eval("("+s+")");
			if(r['data']){
				rdata = r['data'];
				$('.guest_name').each(function(){
					guest = $(this).html();
					node = $(this).parent().parent();
					node_parent = $(this).parent().parent().parent()
					if(rdata[guest]){
						char_str = "<b>["+rdata[guest]['faction']+"]</b> <a href='http://cn.wowarmory.com/character-sheet.xml?"+rdata[guest]['charUrl']+"' target='_blank'>"+rdata[guest]['name']+"</a> <b>["+rdata[guest]['guildName']+"] </b>"+ 
		rdata[guest]['battleGroup']+" | "+rdata[guest]['realm']+" | "+rdata[guest]['race']+" | "+rdata[guest]['class']+" | "+rdata[guest]['level']+"级";
		
						item_arr = rdata[guest][rdata[guest]['name']];
						item_len = item_arr.length;
						var item_str = "";
						for(j=0;j<item_len;j++){
							item_str = item_str + "<image src='"+item_arr[j]['backimage']+"' height='22' width='22' onmouseover='moin(this,"+item_arr[j]['id']+")' onmouseout='hideItem("+item_arr[j]['id']+")'/> <input type='hidden' id='"+item_arr[j]['id']+"' /> "
						}
						if(!node_parent.children(".armory").html()){
							//alert(node.html());
							node_parent.children(".item").remove();
							node.after(" <p class='item'>"+item_str+"</p> ");
							node.after(" <p class='armory'>"+char_str+"</p> ");
						}
						
					}
					else{
						node_parent.children(".item").remove();
						node.after(" <p class='item'></p> ");		
					}
				});
			}
			else{
				
				$('.guest_name').each(function(){
					node = $(this).parent().parent();
					node_parent = $(this).parent().parent().parent();
					
										
					
				});
			}
			
		});
}

function img_limit(w,h){
	img_w_max = "500";
	img_h_max = "500";
	if(w != "" && h !=""){
		if(w > img_w_max || h > img_h_max ){
			ratio = w / h;
			if(w > h){
				w = img_w_max;
				h = Math.round(w/ratio);
			}
			else{
				h = img_h_max;
				w = Math.round(h*ratio);
			}
			return Array(w,h);
		}		
	}
	return Array(w,h);
}

//调用文本编辑器插件：	

              

</script>

<body>
<include file="Public:channel" />

<div >
	
	<div style="float:left">
	<table width="600"  border="1" cellpadding="0" cellspacing="0">
		  <tr>
		    <td colspan="3"><div align="center"><span class="STYLE1">公告</span></div></td>
		  </tr>
		  <tr>  
			<td width="50%"><div align="center">公告标题</div></td>
			<td width="20%"><div align="center">发布人</div></td>
			<td width="30%"><div align="center">发布时间</div></td>
		  </tr>
		  
	<volist name='bull_list' id='one'>
		  <tr>
		    <td><div align="left"><a href="__APP__/bulletin/bull_show/bid/{$one.id}">{$one.title}</a></div></td>
		    <td><div align="center">{$one.author}</a></div></td>
		    <td><div align="center">{$one.time|date='Y-m-d H:i:s',###}</div></td>
		  </tr>
	</volist>		 
		  <tr>
		    <td colspan="3">
		  	  <div align="right">
		 	    <a href='__APP__/bulletin/'>更多</a>
		 	  </div>
		    </td>
		  </tr>
		</table>
		 <br />
		 <br />
		 
	<table width="600"  border="1" cellpadding="0" cellspacing="0">
		  <tr>
		    <td colspan="2"><div align="center"><span class="STYLE1">最新资讯</span></div></td>
		  </tr>
		  <tr>  
			<td width="60%"><div align="center">新闻标题</div></td>
			<td width="33%"><div align="center">发布时间</div></td>
		  </tr>
		  
	<volist name='news_list' id='two'>
		  <tr>
		    <td><div align="left"><a href="__APP__/News/show/nid/{$two.News_id}">{$two.News_title}</a></div></td>
		    <td><div align="center">{$two.News_time|date='Y-m-d H:i:s',###}</div></td>
		  </tr>
	</volist>		 
		  <tr>
		    <td colspan="2">
		  	  <div align="right">
		 	    <a href='__APP__/News/'>更多</a>
		 	  </div>
		    </td>
		  </tr>
		</table>
		 <br />
		 <br />
	</div>
	
	
	<div id="guestbook" style="float:right">
	
	
	</div>
</div>
<br /><br /><br />
<include file="Public:footer" />
 